package queue;

/**
 * @author zhangguisong
 * @date 2022-10-24 14:42
 */
public class Queue<E> {
    private int front;
    private int rear;
    private int size;
    private int maxCapicity;
    private Object[] values;

    public Queue() {
        this.front = -1;
        this.rear = -1;
        this.size = 0;
        this.maxCapicity = 10;
        this.values = new Object[maxCapicity];
    }

    public boolean push(E value) {
        int location = size;
        if (isFull()) {
            this.values[location] = value;
            size++;
            rear++;
        }
        return false;
    }

    public boolean isFull() {
        return size < this.maxCapicity;
    }

    public boolean poll() {
        if (!isEmpty()) {
            front++;
            return true;
        }
        return false;
    }

    public E getHeader() {

        if (!isEmpty()) {
            return (E) values[front +1 ];
        }
        return null;
    }

    public boolean isEmpty() {
        return front == rear && size == 0;
    }

    public static void main(String[] args) {
        Queue<String> queue = new Queue<>();
        queue.push("z");
        queue.push("g");
        queue.push("s");
        String header = queue.getHeader();
        System.out.println(queue.size);
        System.out.println(header);
    }
}
